﻿/*
-----------------------------------------------------------------------------
This source file is part of Cell Cloud.

Copyright (c) 2009-2012 Cell Cloud Team (cellcloudproject@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#include "CellStableHeaders.h"
#include "CellSQLiteResultSet.h"

namespace cell
{

//---------------------------------------------------------------------------
SQLiteMetaData::SQLiteMetaData(void)
{
}
//---------------------------------------------------------------------------
SQLiteMetaData::~SQLiteMetaData(void)
{
}


//---------------------------------------------------------------------------
SQLiteResultSet::SQLiteResultSet(void)
	: mRowCursor(0)
	, mMaxRowNum(0)
	, mCurrentRow(NULL)
{
}
//---------------------------------------------------------------------------
SQLiteResultSet::~SQLiteResultSet(void)
{
}
//---------------------------------------------------------------------------
bool SQLiteResultSet::absolute(int cursor)
{
	if (cursor >= mMaxRowNum)
		return false;

	mRowCursor = cursor;
	return true;
}
//---------------------------------------------------------------------------
bool SQLiteResultSet::relative(int cursor)
{
	return false;
}
//---------------------------------------------------------------------------
bool SQLiteResultSet::first(void)
{
	mRowCursor = 0;
	return true;
}
//---------------------------------------------------------------------------
bool SQLiteResultSet::last(void)
{
	mRowCursor = mMaxRowNum - 1;
	return true;
}
//---------------------------------------------------------------------------
bool SQLiteResultSet::next(void)
{
	// 游标是否已经到最后一行
	if (mRowCursor >= mMaxRowNum - 1)
		return false;

	++mRowCursor;
	return true;
}
//---------------------------------------------------------------------------
bool SQLiteResultSet::previous(void)
{
	if (mRowCursor == 0)
		return false;

	--mRowCursor;
	return true;
}
//---------------------------------------------------------------------------
bool SQLiteResultSet::isFirst(void)
{
	return false;
}
//---------------------------------------------------------------------------
bool SQLiteResultSet::isLast(void)
{
	return false;
}
//---------------------------------------------------------------------------
char SQLiteResultSet::getChar(int columnIndex)
{
	return '\0';
}
//---------------------------------------------------------------------------
char SQLiteResultSet::getChar(const String& label)
{
	return '\0';
}
//---------------------------------------------------------------------------
int SQLiteResultSet::getInt(int columnIndex)
{
	return 0;
}
//---------------------------------------------------------------------------
int SQLiteResultSet::getInt(const String& columnLabel)
{
	return 0;
}
//---------------------------------------------------------------------------
long SQLiteResultSet::getLong(int index)
{
	return 0;
}
//---------------------------------------------------------------------------
long SQLiteResultSet::getLong(const String& label)
{
	return 0;
}
//---------------------------------------------------------------------------
int64 SQLiteResultSet::getInt64(int index)
{
	return 0;
}
//---------------------------------------------------------------------------
int64 SQLiteResultSet::getInt64(const String& label)
{
	return 0;
}
//---------------------------------------------------------------------------
String SQLiteResultSet::getString(int index)
{
	return "";
}
//---------------------------------------------------------------------------
String SQLiteResultSet::getString(const String& label)
{
	return "";
}
//---------------------------------------------------------------------------
bool SQLiteResultSet::getBool(int index)
{
	return false;
}
//---------------------------------------------------------------------------
bool SQLiteResultSet::getBool(const String& label)
{
	return false;
}
//---------------------------------------------------------------------------
int SQLiteResultSet::getRaw(const String& label, char* dst, int offset, int length)
{
	return 0;
}
//---------------------------------------------------------------------------
int64 SQLiteResultSet::getRaw(const String& label, char* dst, int64 offset, int64 length)
{
	return 0;
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateChar(int index, char value)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateChar(const String& label, char value)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateInt(int index, int value)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateInt(const String& label, int value)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateLong(int index, long value)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateLong(const String& label, long value)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateInt64(int index, int64 value)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateInt64(const String& label, int64 value)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateString(int index, const String& value)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateString(const String& label, const String& value)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateBool(int index, bool value)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateBool(const String& label, bool value)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateRaw(const String& label, char* src, int offset, int length)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::updateRaw(const String& label, char* src, int64 offset, int64 length)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::beginAdd(void)
{
	mRowCursor = 0;
}
//---------------------------------------------------------------------------
void SQLiteResultSet::endAdd(void)
{
	mCurrentRow = getRowSet(mRowCursor);
	++mRowCursor;
	mMaxRowNum = mRowCursor;
}
//---------------------------------------------------------------------------
void SQLiteResultSet::addDataByColumn(int columnIndex, char* column, char* value)
{
	// 更新 MetaData
	//mMetaData.updateColumn(column, columnIndex);

	RowSet* row = NULL;
	RowSetMap::iterator iter = mRowSets.find(mRowCursor);
	if (iter == mRowSets.end())
	{
		// 没有该行记录，新建
		row = CELL_NEW RowSet();
		mRowSets.insert(RowSetMap::value_type(mRowCursor, row));
	}
	else
	{
		row = iter->second;
	}
	row->set(columnIndex, value);
}
//---------------------------------------------------------------------------
SQLiteResultSet::RowSet* SQLiteResultSet::getRowSet(int index)
{
	RowSetMap::const_iterator iter = mRowSets.find(index);
	if (iter != mRowSets.end())
		return iter->second;
	return NULL;
}



//---------------------------------------------------------------------------
SQLiteResultSet::RowSet::RowSet(void)
{
}
//---------------------------------------------------------------------------
SQLiteResultSet::RowSet::~RowSet(void)
{
}
//---------------------------------------------------------------------------
void SQLiteResultSet::RowSet::set(int columnIndex, const String& value)
{
	mValues.insert(ColumnValueMap::value_type(columnIndex, value));
}
//---------------------------------------------------------------------------
const String& SQLiteResultSet::RowSet::get(int columnIndex) const
{
	ColumnValueMap::const_iterator iter = mValues.find(columnIndex);
	return iter->second;
}

} // end namespace cell
